/*
NOTE:
    load infor of each product from database and put them in variable product
*/
var product = [{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 500,
    "description" : "Apple iPad",
    "rating" : 4.36,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 400,
    "description" : "Apple iPad",
    "rating" : 3.36,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 200,
    "description" : "Apple iPad",
    "rating" : 2.36,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 300,
    "description" : "Apple iPad",
    "rating" : 5,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 100,
    "description" : "Apple iPad",
    "rating" : 1.36,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 900,
    "description" : "Apple iPad",
    "rating" : 4.6,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 800,
    "description" : "Apple iPad",
    "rating" : 3.9,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 700,
    "description" : "Apple iPad",
    "rating" : 5.0,
    "image" :"images/products/ipad/front.jpg",
},{
    "ID":"124erw124wsf",
    "title": "Apple iPad MD328LL/A (16GB, Wi-Fi, White) NEWEST MODE",
    "company": "Apple Inc.",
    "price": 600,
    "description" : "Apple iPad",
    "rating" : 4.36,
    "image" :"images/products/ipad/front.jpg",
}];

$.fn.stars = function(){
    return $(this).each(function() {
        $(this).html($('<span />').width(Math.max(0, (Math.min(5, parseFloat($(this).html())))) * 16));
    });
}
/* load product list */
function load_list(){
    num = 0;
    $.each(product,function(index,value){
        num = num + 1;
        id = index + 1;
        $('#products').append('<li class="product" data-id="id-'+id+'">'+
                           '<a href="'+value.ID+'" class="product-wrapper">'+
                                '<img width="270" height="180" src="'+value.image+'" class="attachment-shop_catalog wp-post-image" alt="thumbnail_15" title="thumbnail_15">'+
                                '<h3 class="product-title">'+value.title+'</h3>'+
                                '<div class="excerpt"><p><span class="stars" id="'+id+'">'+value.rating+'</span></p><p class="hidden_star" style="display:none">'+value.rating+'</p></div>'+
                                '<span class="price"><del></del><span class="amount">$'+value.price+'</span></span>'+
                            '</a>'+
                            '<a href="#" rel="nofollow" data-product_id="126" class="button">View Details</a>'+
                        '</li>');
        $('span#'+id).stars();
    });
    height = 60 + Math.round(num/3) * 392;
    $('#products').css('height',Math.round(num/3) * 392);
    $('#main').css('height',height);
};
/*------------------*/
$(document).ready(function(){ 
    load_list();
});